#include <iostream>
#include <map>
#include <string>

using namespace std;

int lengthOfLongestSubstring(string s) {
    // Start typing your C/C++ solution below
    // DO NOT write int main() function
    if(s.length() == 0)
        return 0;
    map<char, int> posRead;
    map<char, int> posWrite;
    map<char, int> *pRead = &posRead;
    map<char, int> *pWrite = &posWrite;
    int res = 0;
    for(int i=0; i<s.length(); ++i){
        map<char, int>::iterator it = pRead->find(s[i]);
        if(it != pRead->end()){
            // update posmap, remove duplicate and before char
            int begin = it->second;
            pWrite->clear();
            for(it=pRead->begin(); it!=pRead->end(); ++it){
                if(it->second > begin){
                    (*pWrite)[it->first] = it->second;
                }
            }
            map<char, int> *pTmp = pWrite;
            pWrite = pRead;
            pRead = pTmp;
        }
        // add this char
        (*pRead)[s[i]] = i;
        int length = pRead->size();
        if(length > res){
            res = length;
        }
    }
    return res;
}



int main(){

    cout<<lengthOfLongestSubstring("wlrbbmqbhcdarzowkkyhiddqscdxrjmowfrxsjybldbefsarcbynecdyggxxpklorellnmpapqfwkhopkmco")<<endl;

}